<?php

abstract class Quad_Form_Element extends Quad_Html_Element {

	protected $_label;
	public $form;
		
	public function __construct($tagName, $labelText, $value) {
		parent::__construct($tagName);
		$this->_label = new Quad_Form_Element_Label($this, $labelText);
		$this->setValue($value);
		$this->addClassName('q-form-element');
	}
	
	public function getValue() {
		return $this->getAttribute('value');
	}
	
	public function setValue($v) {
		$this->setAttribute('value',$v);
		return $this;
	}
	
	public function addValidator() {}
	public function removeValidator() {}
	public function required() {}
	public function optional() {}
	public function addFilter() {}
	public function removeFilter() {}
	public function isInvalid() {}
	public function getErrorMsg() {}
	
	public function __set($p, $v) {
		if ($p == 'value') {
			$this->setValue($v);
		}
		elseif ($p == 'label') {
			if ($v instanceof Quad_Form_Element_Label) {
				$this->_label = $v;
			}
			else {
				$this->_label->text = (string) $v;
			}
		}
		else {
			parent::__set($p,$v);
		}
	}
	
	public function __get($p) {
		if ($p == 'value') {
			return $this->getValue();
		}
		elseif ($p == 'label') {
			return $this->_label;
		}		
		else {
			return parent::__get($p);
		}		
	}	
    
}
